import { HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PaginationList } from '../model/message';
import { ProductCate, ProductCateWithChildren } from '../model/proudctCate';
import { CommonApi } from './commonApi';
import { RequestService } from './request.service';

@Injectable({
  providedIn: 'root'
})

export class ProductCategoryApiService extends CommonApi<ProductCate>{


  constructor(
    private request: RequestService,
  ) {
    super(request, '/productCategory');
  }

  public updataShowStatus(data): Observable<any> {
    const url = this.baseUrl + '/update/showStatus';
    return this.request.post(url, data);
  }

  public updateNavStatus(data): Observable<any> {
    const url = this.baseUrl + '/update/navStatus';
    return this.request.post(url, data);
  }

  public fetchListWithChildren(): Observable<ProductCateWithChildren[]> {
    const url = this.baseUrl + '/list/withChildren';
    return this.request.get<ProductCateWithChildren[]>(url);
  }

  public fetchListInParent(parentId?: number, params?: HttpParams): Observable<PaginationList<ProductCate>> {
    const url = this.baseUrl +  '/list/' + parentId;
    return this.request.get<PaginationList<ProductCate>>(url, params);
  }

  public fetchAllInParent(parentId: number): Observable<Array<ProductCate>> {
    const url = this.baseUrl + '/listAll/' + parentId;
    return this.request.get(url);

  }
}
